<?php
/**
 * Note: 游戏服通知队列
 */
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Redis;

class GameNotifyJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    // 频道名称
    const PUBLISH_CHANNEL = 'p2s';

    public $type;
    public $event;
    public $param;
    public $extend;

    /**
     * GameNotifyJob constructor.
     * @param string $type
     * @param string $event
     * @param array $param
     * @param array $extend
     */
    public function __construct(string $type = '', string $event = '', array $param = [], array $extend = [])
    {
        $this->type = $type;
        $this->event = $event;
        $this->param = $param;
        $this->extend = $extend;
    }

    /**
     *
     */
    public function handle()
    {
        Redis::connection('game')->publish(self::PUBLISH_CHANNEL, json_encode([
            'tp'    => $this->type,
            'name'  => $this->event,
            'param' => $this->param,
            'extend' => $this->extend,
        ]));
    }
}
